package com.ruoyi.system.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.system.domain.HyrjMachine;
import com.ruoyi.system.service.IHyrjMachineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.HyrjMachineFaultsMapper;
import com.ruoyi.system.domain.HyrjMachineFaults;
import com.ruoyi.system.service.IHyrjMachineFaultsService;

/**
 * 洗衣机故障管理，用于记录洗衣机的故障信息和维修情况Service业务层处理
 *
 * @author ruoyi
 * @date 2024-03-08
 */
@Service
public class HyrjMachineFaultsServiceImpl implements IHyrjMachineFaultsService {
    @Autowired
    private HyrjMachineFaultsMapper hyrjMachineFaultsMapper;
    @Autowired
    private IHyrjMachineService hyrjMachineService;

    /**
     * 查询洗衣机故障管理，用于记录洗衣机的故障信息和维修情况
     *
     * @param id 洗衣机故障管理，用于记录洗衣机的故障信息和维修情况主键
     * @return 洗衣机故障管理，用于记录洗衣机的故障信息和维修情况
     */
    @Override
    public HyrjMachineFaults selectHyrjMachineFaultsById(Long id) {
        return hyrjMachineFaultsMapper.selectHyrjMachineFaultsById(id);
    }

    /**
     * 查询洗衣机故障管理，用于记录洗衣机的故障信息和维修情况列表
     *
     * @param hyrjMachineFaults 洗衣机故障管理，用于记录洗衣机的故障信息和维修情况
     * @return 洗衣机故障管理，用于记录洗衣机的故障信息和维修情况
     */
    @Override
    public List<HyrjMachineFaults> selectHyrjMachineFaultsList(HyrjMachineFaults hyrjMachineFaults) {
        return hyrjMachineFaultsMapper.selectHyrjMachineFaultsList(hyrjMachineFaults);
    }

    /**
     * 新增洗衣机故障管理，用于记录洗衣机的故障信息和维修情况
     *
     * @param hyrjMachineFaults 洗衣机故障管理，用于记录洗衣机的故障信息和维修情况
     * @return 结果
     */
    @Override
    public int insertHyrjMachineFaults(HyrjMachineFaults hyrjMachineFaults) {
        HyrjMachine hyrjMachine = hyrjMachineService.selectHyrjMachineByNo(hyrjMachineFaults.getWashingMachineSerial());
        if (null != hyrjMachine) {
            hyrjMachine.setMachineStatus("3");
            hyrjMachineService.updateHyrjMachine(hyrjMachine);
        }
        hyrjMachineFaults.setRepairStatus("1");
        return hyrjMachineFaultsMapper.insertHyrjMachineFaults(hyrjMachineFaults);
    }

    /**
     * 修改洗衣机故障管理，用于记录洗衣机的故障信息和维修情况
     *
     * @param hyrjMachineFaults 洗衣机故障管理，用于记录洗衣机的故障信息和维修情况
     * @return 结果
     */
    @Override
    public int updateHyrjMachineFaults(HyrjMachineFaults hyrjMachineFaults) {

        return hyrjMachineFaultsMapper.updateHyrjMachineFaults(hyrjMachineFaults);
    }


    @Override
    public int updateHyrjMachine(HyrjMachineFaults hyrjMachineFaults) {

        hyrjMachineFaults.setRepairStatus("2");
        hyrjMachineFaults.setRepairTime(new Date());
        hyrjMachineFaultsMapper.updateHyrjMachineFaults(hyrjMachineFaults);

        HyrjMachine hyrjMachine = hyrjMachineService.selectHyrjMachineByNo(hyrjMachineFaults.getWashingMachineSerial());
        hyrjMachine.setMachineStatus("1");
        return hyrjMachineService.updateHyrjMachine(hyrjMachine);

    }

    public int update(HyrjMachineFaults hyrjMachineFaults) {
        return hyrjMachineFaultsMapper.updateHyrjMachineFaults(hyrjMachineFaults);
    }

    /**
     * 批量删除洗衣机故障管理，用于记录洗衣机的故障信息和维修情况
     *
     * @param ids 需要删除的洗衣机故障管理，用于记录洗衣机的故障信息和维修情况主键
     * @return 结果
     */
    @Override
    public int deleteHyrjMachineFaultsByIds(Long[] ids) {
        return hyrjMachineFaultsMapper.deleteHyrjMachineFaultsByIds(ids);
    }

    /**
     * 删除洗衣机故障管理，用于记录洗衣机的故障信息和维修情况信息
     *
     * @param id 洗衣机故障管理，用于记录洗衣机的故障信息和维修情况主键
     * @return 结果
     */
    @Override
    public int deleteHyrjMachineFaultsById(Long id) {
        return hyrjMachineFaultsMapper.deleteHyrjMachineFaultsById(id);
    }
}
